package user

import (
	"gin/app/http/global"
	"time"
)

type UserModel struct {
	UserId    int       `json:"user_id" gorm:"primaryKey"`
	UserName  string    `json:"user_name" gorm:"index"`
	Password  string    `json:"password"`
	Sex       uint8     `json:"sex"`
	Mail      string    `json:"mail"`
	IsDeleted byte      `json:"is_deleted"`
	CreateAt  time.Time `json:"create_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (UserModel) TableName() string {
	return "zlg_users"
}

func CheckUser(users *UserModel) (UserModel, bool) {

	var result UserModel
	db := global.DB
	res := db.Where("user_name = ? and password = ? ", users.UserName, users.Password).First(&result)

	if res.RowsAffected == 0 {

		return result, false
	}

	return result, true
}
